﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InstallWizard.Model
{
    public class AppFileInfo
    {
        public string SourceFile { get; set; }
        /// <summary>
        /// 目标文件夹。相对于压缩文件的根。如果为根文件夹，则保留为空
        /// </summary>
        public string TargetDir { get; set; }
        /// <summary>
        /// 处理方式：更新、忽略、升级前运行，升级后运行
        /// </summary>
        public EProceed Proceed { get; set; }
       
        public EFileType FileType { get; set; }

        public string FileTypeCn
        {
            get { return GetFileTypeCn(); }
            set { SetFileTypeCn(value); }
        }

        private void SetFileTypeCn(string value)
        {

            switch (value)
            {
                case "主程序":
                    FileType = EFileType.MainProgram;
                    break;
                case "卸载器":
                    FileType = EFileType.Unistaller;
                    break;
                case "程序维护器":
                    FileType = EFileType.Maintainer;
                    break;
                default:
                    FileType = EFileType.Normal;
                    break;
            }
        }

        private string GetFileTypeCn()
        {
            switch (FileType)
            {
                case EFileType.Normal:
                    return "常规";
                case EFileType.MainProgram:
                    return "主程序";
                case EFileType.Unistaller:
                    return "卸载器";
                case EFileType.Maintainer:
                    return "程序维护器";
                default:
                    return "常规";
            }
        }

        public string Proceedcn
        {
            get
            {
                return GetProceedCn();
            }
            set
            {
                SetProceed(value);
            }
        }

        private string GetProceedCn()
        {
            switch (Proceed)
            {
                case EProceed.Update:
                    return "更新";
                case EProceed.Ignore:
                    return "忽略";
                case EProceed.RunBeforeUpdate:
                    return "升级前运行";
                case EProceed.RunAfterUpdate:
                    return "升级后运行";
                default:
                    return "忽略";
            }
        }

        private void SetProceed(string proceedCn)
        {
            switch (proceedCn)
            {
                case "更新":
                    Proceed = EProceed.Update;
                    break;
                case "升级前运行":
                    Proceed = EProceed.RunBeforeUpdate;
                    break;
                case "升级后运行":
                    Proceed = EProceed.RunAfterUpdate;
                    break;
                default:
                    Proceed = EProceed.Ignore;
                    break;
            }
        }
        public AppFileInfo() { }
        public AppFileInfo(string srcFile,string targDir= "")
        {
            AddFile(srcFile, targDir);
        }
        public void AddFile(string sourceFile,string targDir="")
        {
            SourceFile = sourceFile;
            TargetDir = targDir;
            FileType = EFileType.Normal;
            string ext = Path.GetExtension(sourceFile);
            Proceed = EProceed.Update;
            if (!string.IsNullOrEmpty(ext))
            {
                if(ext==".ini"||ext==".dat"||ext==".db"||ext==".lic"||ext=="")
                {
                    Proceed = EProceed.Ignore;
                }
            }    
        }
      
        
    }
    public enum EProceed 
    {
        Update,Ignore,RunBeforeUpdate,RunAfterUpdate
    }
    public enum EFileType
    {
        Normal,MainProgram,Unistaller,Maintainer
    }
}
